package lagou.cn.homework

case class UserInfo(userName:String,location:String,startTime:Int,duration:Int)

object Test03 {
  def main(args: Array[String]): Unit = {

    val userInfoList:List[UserInfo] = List(
      UserInfo("UserA", "LocationA", 8, 60),
      UserInfo("UserA", "LocationA", 9, 60),
      UserInfo("UserA", "LocationB", 10, 60),
      UserInfo("UserA", "LocationB", 11, 80)
    )

    val userMap = userInfoList.groupBy(t => t.userName+"," + t.location)

    var firstTime = 0

    //对map集合中的value值进行操作
    val totalMap = userMap.mapValues(t =>{
      //      取第一个时间
      firstTime = t.head.startTime
      //      对时间区间求和
      var sum = t.map(x=> x.duration).sum
      sum
    })
    //    分别打印结果
    totalMap.foreach{
      case (datas,sumTime)=>println(s"$datas,$firstTime,$sumTime")
    }
  }
}
